package org.hu.service.impl;

import org.hu.entity.pojo.Category;
import org.hu.mapper.CategoryMapper;
import org.hu.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    // 新增一个分类
    public void addCategory(String name) {
        Category category = new Category();
        category.setName(name);
        category.setCreateTime(LocalDate.now());
        category.setUpdateTime(LocalDate.now());
        categoryMapper.insert(category);
    }

    // 删除一个分类
    public void deleteCategory(Integer id) {
        categoryMapper.deleteById(id);
    }

    // 更新一个分类
    public void updateCategory(Category category) {
        category.setUpdateTime(LocalDate.now());
        categoryMapper.updateById(category);
    }

    // 查询所有分类
    public List<Category> listCategory() {
        return categoryMapper.select();
    }
}
